uniform sampler2D Texture;
uniform int Width;
uniform int Height;
uniform int KernelSize;

void main(void)
{
    vec2 coord = vec2(float(gl_FragCoord.x) / float(Width),  float(gl_FragCoord.y) / float(Height));
    float offsetX  = 1.0/float(Width);
    float offsetY  = 1.0/float(Height);

    /**///MEDIAN
    float conv = 0.0;

    for (int j = -KernelSize/2; j <= KernelSize/2; j++)
    {
        for (int i = -KernelSize/2; i <= KernelSize/2; i++)
        {
            conv += texture2D(Texture, vec2(coord.x + float(i)*offsetX, coord.y + float(j)*offsetY)).z;
        }
    }
    conv /= float(KernelSize * KernelSize);
    /**/

    /*///GAUSSIAN
    float conv = 0.0;
    conv += texture2D(Texture, vec2(coord.x - offsetX, coord.y - offsetY)).z * 1.0;
    conv += texture2D(Texture, vec2(coord.x - offsetX, coord.y          )).z * 2.0;
    conv += texture2D(Texture, vec2(coord.x - offsetX, coord.y + offsetY)).z * 1.0;

    conv += texture2D(Texture, vec2(coord.x          , coord.y - offsetY)).z * 2.0;
    conv += texture2D(Texture, vec2(coord.x          , coord.y          )).z * 4.0;
    conv += texture2D(Texture, vec2(coord.x          , coord.y + offsetY)).z * 2.0;

    conv += texture2D(Texture, vec2(coord.x + offsetX, coord.y - offsetY)).z * 1.0;
    conv += texture2D(Texture, vec2(coord.x + offsetX, coord.y          )).z * 2.0;
    conv += texture2D(Texture, vec2(coord.x + offsetX, coord.y + offsetY)).z * 1.0;
    conv /= 16.0;
    /**/

    //gl_FragColor = vec4(conv, conv, conv, conv);
    gl_FragDepth = conv;
}
